<template>
	<view class="container">
		<template v-if="dataLists.length > 0">
			<view v-for="(item,index) in dataLists" :key="index" class="u-padding-20 z-b-r white-bg u-margin-bottom-20">
				<view class="u-margin-bottom-20 u-margin-top-30">
					<text>项目名称：{{ item.project_name || "加载……"}}</text>
				</view>
				<view class="u-margin-bottom-20">
					<text>项目地址：{{ item.project_address || "加载……" }}</text>
				</view>
				<view class="u-margin-bottom-20">
					<text>项目开始日期：{{ item.project_begin_date || "加载……" }}</text>
				</view>
				<view class="u-margin-bottom-20">
					<text>项目经理姓名：{{ item.pm_name || "加载……" }}</text>
				</view>
				<view class="u-margin-bottom-20">
					<text>项目经理电话：{{ item.pm_phone || "加载……" }}</text>
				</view>
				<view class="u-margin-bottom-20 z-b-r" style="box-shadow: 0 0 9rpx #C0C0C0;">
					<u-cell-item @click="gotoWorkerDetail(item)" icon="order" title="查看工作量信息"></u-cell-item>
				</view>
			</view>
		</template>
		<template v-else>
			<empty-data tipText="无任何项目"></empty-data>
		</template>
	</view>
</template>

<script>
	import {mapState} from "vuex"
	export default {
		data() {
			return {
				projectStatus:0,
				dataLists:[]
			};
		},
		computed:{
			...mapState({
				token:"token",
				wkID:"wkID"
			})
		},
		onLoad(params) {
			this.projectStatus = params.projectStatus;
			this.getDataList()
		},
		methods:{
			async getDataList(){
				let {token,wkID,projectStatus} = this;
				this.$loading("正在加载");
				let res = await this.$network({
					api:"main",
					data:{
						action:"wkProjectAdmin/getUnderwayProject",
						data:{
							token,
							wkID,
							projectStatus:parseInt(projectStatus)
						}
					}
				})
				
				if(res.status === 0){
					this.dataLists = res.data;
				} 
				
				//获取参与过的其他项目（被踢出）
				let historyProject = await this.$network({
					api:"main",
					data:{
						action:"wkProjectAdmin/getWKhistoryProject",
						data:{
							wkID,
							type:"onWKid",
							token
						}
					}
				})
				
				if(historyProject.status === 0){
					//存在获取项目信息
					let tasks = [];
					historyProject.data.forEach(item=>{
						tasks.push(this.$network({
							api:"main",
							data:{
								action:"projectAdmin/getProjectDetail",
								data:{
									id:item.projectID
								}
							}
						}))
					})
					
					let taskRes = await Promise.all(tasks);
					uni.hideLoading();
					taskRes.forEach(item=>{
						if(item.status === 0){
							item.data[0].worker_ids.push()
							this.dataLists.push(item.data[0]);
						}
					})
					
					historyProject.data.forEach(item1 => {
						this.dataLists.forEach((item2,index) => {
							if(item1.projectID == item2._id){
								let {wkID,salaryWay,drillDeepCount,signCountDay} = item1
								this.dataLists[index].worker_ids.push({wkID,salaryWay,drillDeepCount,signCountDay});
							}
						})
					})
				} else {
					uni.hideLoading();
				}
			},
			gotoWorkerDetail(item){
				let {wkID} = this;
				let jobInfoTJ = {};
				item.worker_ids.forEach(d => {
					if(wkID == d.wkID){
						jobInfoTJ = d;
					}
				})
				uni.navigateTo({url:`../history-project-wkInfo/history-project-wkInfo?wks=${item.worker_ids.length}&deep=${item.drillDeepCount}&day=${item.signCountDay}&projectID=${item._id}&C=${item.salary_standard_chi}&D=${item.salary_standard_day}&TJ=${encodeURIComponent(JSON.stringify(jobInfoTJ))}`})
			}
		}
	}
</script>

<style lang="scss">

</style>
